<?php
/* explain:
 * Project:     
 * File:        Job.php
 *
 * @ link 		http://www.../lib/
 * @ Email		ldmmyx@hotmail.com
 * @ copyright 	2007  Ling Deming
 * @ author 	ivan.ling  Ling Deming
 * @ version 	1.0
 *
 */
include_once("utils/CommonUtils.php");

class MenuImpl extends CommonUtils
{
	function __construct($DBTag = 'system')
	{
		parent::__construct();
		
		$this->DBTag 	= $DBTag;
	}

	/* get data via ID
	 *
	 * @param  int    id
	 * @return mixed  false:
	 */
	public function getById($id)
	{
		$sql = "SELECT * FROM menu WHERE id = $id";
		
		return $this->getRow($this->DBTag, $sql);
	}

	/* 
	 *
	 * @param  string 	groupid		
	 * @param  string 	strOrders	
	 * @param  string  	name 	
	 * @param  string 	namecn 
	 * @param  string 	url			menu url  
	 * @param  datetime	remark
	 * @param  datetime status
 	 * @return boolean 	true or fail
	 */
	public function add($groupid, $strOrders, $name, $url, $remark, $status = 'normal')
	{
		$sql = "INSERT INTO menu SET groupid = '$groupid', orders='$strOrders', name = '$name', url = '$url', remark = '$remark', status='$status'";
		
		return $this->insert($this->DBTag, $sql);
	}
	
	/* modify menu
	 *
	 * @param  string 	id			modify menu id
	 * @param  string 	groupid		
	 * @param  string 	strOrders	
	 * @param  string  	name 	
	 * @param  string 	namecn 
	 * @param  string 	url			menu url  
	 * @param  datetime	remark
	 * @param  datetime status
 	 * @return boolean 	true or fail
	 */
	public function edit($id, $groupid, $strOrders, $name, $url, $remark)
	{
		$sql = "UPDATE menu SET groupid = '$groupid', orders='$strOrders', name = '$name', url = '$url', remark = '$remark' WHERE id = '$id'";
		
		return $this->update($this->DBTag, $sql);
	}
		
	/* delete menu
	 *
	 * @param  int    	id
	 * @param  return 	boolean
	 */
	public function delete($id)
	{				
		$sql = "DELETE FROM menu WHERE id = $id";
		
		return $this->update($this->DBTag, $sql);
	}
	
	public function lists($where, $order, $page, $discount, $url = '')
	{
		return $this->getPageRows($this->DBTag, '*', "menu $where", $order, $page, $discount, $url);	
	}
	

}
?>
